package com.video.controller.webcon;

import com.qf.entity.ResultData;
import com.video.commons.loginaop.LoginUser;
import com.video.commons.loginaop.MustLogin;
import com.video.commons.sendaop.SocketSend;
import com.video.commons.utils.ClientStatusUtil;
import com.video.entity.ClientMsg;
import com.video.entity.Webcon;
import com.video.netty.send.VolumeSend;
import com.video.service.client.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/client")
public class ClientsController {

    @Autowired
    private IClientService clientService;

    /**
     * 分控查询终端列表
     * @return
     */
    @RequestMapping("/listByWebcon")
    @MustLogin
    public String clientList(String keyword, Model model, @LoginUser Webcon webcon){
        List<ClientMsg> clientMsgs = clientService.queryClientsByWebcon(keyword, webcon.getAccount());
        model.addAttribute("clients", clientMsgs);
        model.addAttribute("listenStatus", ClientStatusUtil.getClientListenerMap());
        model.addAttribute("keyword", keyword);
        return "webcon/clientlist";
    }

    /**
     * 修改终端音量
     * @return
     */
    @RequestMapping("/updateVolume")
    @SocketSend(sendClass = VolumeSend.class, params = {"#uids", "#volume"})
    @ResponseBody
    public ResultData<String> updateVolume(@RequestParam("uids[]") String[] uids, int volume){
        clientService.updateVolume(volume, uids);
        return new ResultData<String>().setData("succ");
    }

}
